<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <p><input type= "checkbox"/>123 </p>
        <p><input type= "checkbox"/>456</p>
        <p><input type= "checkbox"/>789 </p>
        <p><input type= "checkbox"/>abc</p>
    </form>
    
    <button>全选</button>
    <button>全不选</button>
    <button>反选</button>
</body>

<script>
    let but = document.getElementsByTagName('button');
    let input = document.getElementsByTagName('input');

    //全选
    but[0].onclick = function(){
        for(let i = 0; i < input.length; i++){
            input[i].checked = true;
        }
    }

    //全不选
    but[1].onclick = function(){
        for(let i = 0; i < input.length;i++){
            input[i].checked = false;
        }
    }

    //反选
    but[2].onclick = function(){
        for(let i = 0; i < input.length;i++){
            input[i].checked = !input[i].checked; 
        }
    }
</script>


</html>